/**
 * 严肃声明：
 * 开源版本请务必保留此注释头信息，若删除我方将保留所有法律责任追究！
 * 本系统已申请软件著作权，受国家版权局知识产权以及国家计算机软件著作权保护！
 * 可正常分享和学习源码，不得用于违法犯罪活动，违者必究！
 * Copyright (c) 2020 陈尼克 all rights reserved.
 * 版权所有，侵权必究！
 */

import Vue from 'vue'
import Vuex from 'vuex'
import state from './state'
import actions from './actions'
import mutations from './mutations'

import { Sidebar, SidebarItem } from 'vant';

Vue.use(Sidebar);
Vue.use(SidebarItem);

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    name: '',
    tel: '',
    province_name: '',
    city_name: '',
    region_name: '',
    detail_address: '',
    address_id: '',
    cart_num: '',
    params: [],
  },
  mutations: {
    UpdateAddress(state, text) {
      state.name = text[0]
      state.tel = text[1]
      state.province_name = text[2]
      state.city_name = text[3]
      state.region_name = text[4]
      state.detail_address = text[5]
      state.address_id = text[6]
    },
    AddCart(state, num) {
      state.cart_num = Number(state.cart_num) + Number(num)
    },
    Minus(state, num) {
      state.cart_num = state.cart_num - num
      if(state.cart_num == 0 || state.cart_num < 0){
        state.cart_num = ''
      }
    },
    Cart(state, num){
      state.cart_num = num
      if(num==0){

        state.cart_num = ''
      }
    }
  },
  actions: {
    deafultAddress(context, text) {
      context.commit('UpdateAddress', text)
    },
    addcart(context, num) {
      context.commit('AddCart', num)
    },
    minus(context, num) {
      context.commit('Minus', num)
    },
    cart(context, num){
      context.commit('Cart', num)
    }
  },
  modules: {}
})
